package Summative;

public class Vector
{
  private int startX;
  private int startY;
  private int endX;
  private int endY;
  private double slope;
  
  private double length;
  private double scaledLength;
  private double angle;
  
  private String unitVector;
  
  private int drawCoordX;
  private int drawCoordY;
  private int drawCoordXF;
  private int drawCoordYF;
  
  
  public Vector(int strtX, int strtY, int endX, int endY)
  {
    this.startX = strtX;
    this.startY = strtY;
    this.endX = endX;
    this.endY = endY;
    calculateSlope();
    calculateLengths();
    calculateAngle();
    convertToUnitVec(startX, startY, endX, endY);
    calculateDrawCoords();
  }
  
  public Vector(String unitVector)
  {
    this.unitVector = unitVector;
    this.startX = 0;
    this.startY = 0;
    calculateXUnitVec();
    calculateYUnitVec();
    calculateSlope();
    calculateLengths();
    calculateAngle();
    calculateDrawCoords();
  }
  
  public void calculateDrawCoords()
  {
    drawCoordX = (250 - startX);
    drawCoordY = (250 - startY);
    drawCoordXF = 250 - endX;
    drawCoordYF = (250 - endY); 
  }
  
  public void calculateXUnitVec()
  {
    String[] array;
    array = unitVector.split("i");
    
    endX = Integer.parseInt(array[0])*10;
  }
  
  public void calculateYUnitVec()
  {
    String[] arrayOne;
    arrayOne = unitVector.split("i");
    
    String[] arrayTwo;
    arrayTwo = arrayOne[1].split("\\+");
    
    String[] arrayThree;
    arrayThree = arrayTwo[1].split("j");
    
    endY = Integer.parseInt(arrayThree[0].trim())*10;
  }
  
  public void calculateSlope()
  {
    this.slope = ((endY-startY)/(endX-startX));
  }
  
  public void calculateLengths()
  {
    this.length = Math.sqrt((Math.pow((endX-startX), 2)+Math.pow((endY-startY), 2)));
    this.scaledLength = (length/10);
  }
  
  public void calculateAngle()
  {
    this.angle = Math.atan(((endX-startX)/(endY-startY)));
  }
  
  public void convertToUnitVec(int xInit, int yInit, int xFin, int yFin)
  {
    unitVector = (((xFin-xInit)/10) + "i + " +  ((yFin-yInit)/10) + "j");
  }
  
  public String getUnitVec()
  {
    return this.unitVector;
  }
  
  public int getStrtX()
  {
    return this.startX;
  }
  public int getEndX()
  {
    return this.endX;
  }
  public int getStrtY()
  {
    return this.startY;
  }
  public int getEndY()
  {
    return this.endY;
  }
  public double getSlope()
  {
    return this.slope;
  }
  public double getLength()
  {
    return this.length;
  }
  public double getScaledLength()
  {
    return this.scaledLength;
  }
  public double getAngle()
  {
    return this.angle;
  }
  public int getDrawCoordX()
  {
    return this.drawCoordX;
  }
  public int getDrawCoordY()
  {
    return this.drawCoordY;
  }
  public int getDrawCoordXF()
  {
    return this.drawCoordXF;
  }
  public int getDrawCoordYF()
  {
    return this.drawCoordYF;
  }
}
